<?php
/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-11-7
 * @Time  : 下午1:06
 * @brief :
 */

function  smarty_modifier_format_amount($params,$n = 2) {
    if($n>0){
        $params = $params*pow(10,intval($n));
        $params = floor($params);
        $s = $params/pow(10,intval($n));
    }else{
        $s = floor($params);
    }
    $s = $s."";
    $arr = explode(".",$s);
    $str = "";
    $arr1 = $arr[0];
    $len = strlen($arr1);
    for($i=$len-1,$j=1;$i>=0;$i--,$j++){
        $str=$arr1[$i].$str;
        if($j%3 == 0 && $j<$len){
            $str=','.$str;
        }
    }
    if(isset($arr[1])){
        $str.='.'.$arr[1];
    }
    return $str;

}